package com.ruoyi.smtdashboard.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.smtdashboard.domain.entity.QueryParams;
import com.ruoyi.smtdashboard.domain.entity.Smtdashboard;
import com.ruoyi.smtdashboard.mapper.SmtTableMapper;
import com.ruoyi.smtdashboard.service.SmtTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmtTableServiceImpl implements SmtTableService {

    @Autowired
    SmtTableMapper smtTableMapper;

    @Override
    public PageInfo<Smtdashboard> qreuySmtTable(QueryParams queryParams, boolean bl) {
        Integer size;
        if (bl) {
            size = queryParams.getPageSize(); // 使用参数中的分页大小
        } else {
            size = 300; // 非分页模式强制每页300条
        }

        // 启动分页（MyBatis PageHelper）
        PageHelper.startPage(queryParams.getPageNum(), size);

        // 执行SQL查询
        List<Smtdashboard> list = smtTableMapper.qreuySmtTable(
                queryParams.getYear(),
                queryParams.getMonth(),
                queryParams.getLine()
        );

        // 包装分页结果
        return new PageInfo<>(list);
    }

    @Override
    public int batchSave(List<Smtdashboard> dataList) {
        return smtTableMapper.batchSave(dataList);
    }
}
